<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@include file="/WEB-INF/base.jspf"%>
<!DOCTYPE html>
<html>
<head>
<title>推广链接管理</title>
<style>
	.div-search-tool {
		display:flex;
		align-items:center;
	}
	.div-search-tool .form-control {
		width:200px;
		margin-right:6px;
	}
		.modal-dialog {
		max-width: 1000px;
	}
	#table-tuiguanglianjie {
		margin-top:20px;
	}
	.copy-span-btns {
		margin-left:6px;
	}
	table th,table tr,table td {
	text-align: center;
	vertical-align:middle;
}
</style>
<script src="/js/clipboard.min.js"></script>
</head>
<body>
	<div class="div-search-tool">
		<input class="form-control" id="input-i-account" placeholder="用户账号" />
		<input class="form-control" id="input-i-icode" placeholder="推广链接" />
		<button class="layui-btn layui-btn-radius btn-searchBtn">查询</button>
		<button class="layui-btn layui-btn-radius btn-resetBtn">重置</button>
	</div>
<table id="table-tuiguanglianjie" class="class-tableDataTable table-normal-datatables table table-striped table-bordered table-hover">
		<thead>
			<tr>
				<th>账号</th>
				<th>注册类型</th>
				<th>彩票返点金额</th>
				<th>推广链接</th>
			</tr>
		</thead>
		<tbody>													
		</tbody>
	</table>
	
<!-- 提醒模态框（Modal） -->

<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModal" aria-hidden="true">
    <div class="modal-dialog class-fake-alert">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body" ></div>
            <div class="modal-footer">	      
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>	
	<script>
		//initAllTable()
		//
		$(".table-normal-datatables").DataTable({
	      // "bPaginate": true,
	      "bLengthChange": true,      
	      "bSort": false,
	      // "bInfo": true,
	      "bAutoWidth": false,
	//	         "bServerSide":true,
	      'aLengthMenu':[ 10, 20],
	       "searching": false,
	       "dom": "t<'tableinfo'i<'tableSearch'p>l>",
	//	    "searching": true,l
	       "language": {//语言设置  
	            "lengthMenu": "每页显示 _MENU_ 条记录",     
	            "zeroRecords": "没有检索到数据",
	            "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",     
	            "info": "没有数据",     
	            "oPaginate": {     
	                "sFirst": "首页",     
	                "sPrevious": "前一页",     
	                "sNext": "后一页",     
	                "sLast": "尾页"    
	          	},
	            "search":"搜索:",
	            "infoFiltered":   "(从  _MAX_ 记录中搜索出结果)",
	            "infoEmpty":      "没有找到匹配的信息",
	         },	      
	         "columns": [
						 {"data": "name", },
	                     {"data": "userType", },
	                     {"data": "money",},
	                     {"data": "icode",},
	                 ],	         
	         "ajax": {
	        	 "url": "/admin/findAgentUserList.do",
	        	 "type": "post",
	        	 "data": function(d) {
	        		 return d
	        	 },
	        	 "dataSrc": function(json) {
					var newData = json.data
					var newDataArray = []
					for (var i = 0; i < newData.length; i++) {
						var item = newData[i]
						var newObj = {
							name: item.name,
							money: item.money,
						}
						if (item.icode != null) {
							newObj.userType = "<span>代理</span"
							newObj.icode = "<span>" + item.icode + " </span>" + "<span style='margin-left:10px;' class='copy-span-btns btn btn-default btn-sm'>复制</span>"
						} else {
							newObj.userType = "<span>会员</span"
							newObj.icode = "没有推广链接!"
						}
						newDataArray.push(newObj)
					}
					return newDataArray
	        	 },
	         },
	    })	
	    
	    insertSearchBtn()
 			var copyBtn = new ClipboardJS(".copy-span-btns", {
 			    target: function(trigger) {
 			        return trigger.previousElementSibling
 			    }
 			})		
 			copyBtn.on('success', function(e) {
 				showNoticeModal("复制成功！")
 			    e.clearSelection();
 			});

 			copyBtn.on('error', function(e) {
 				showNoticeModal("复制失败！")
 			});
 			
 			
 			$(".btn-searchBtn").on("click", function(event) {
 				var table = $("#table-tuiguanglianjie").DataTable();
 				var param = {
 					name: $("#input-i-account").val(),
 					icode: $("#input-i-icode").val()
 				};
		        table.settings()[0].ajax.data = param;
		        table.ajax.url("/admin/findTermAgentList.do").load();			
 			})
 			
 			$(".btn-resetBtn").on("click", function(event) {
 				var table = $("#table-tuiguanglianjie").DataTable()
 				$("#input-i-account").val("");
 				$("#input-i-icode").val("");
 				table.ajax.url("/admin/findAgentUserList.do").load();		
 			}) 	
 			
	</script>
</body>
</html>